<?php

include_once 'baseInformatica.php';

if (isset($_GET['mm'])) {
    if ($_GET['mm'] == INTERIOR_SECRET) {
        echo GetAccessToken();
    }
}

//获取access_token；
function GetAccessToken() {
    $appid = APPID;
    $secret = SECRET;
    $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
    return GetToken($url);
}

function GetToken($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $res = curl_exec($ch);
    $access_token = json_decode($res, true);
    if (!isset($access_token['access_token'])) {
        $errcode = $access_token['errcode'];
        return $access_token['errcode'];
    }
    return $access_token['access_token'];
}
